<template>
    <base-breadcrumb class="allPlan">
        <template>
        <title-name title="处理"></title-name>
        <a-card>
            <title-name :title="title"></title-name>
            <a-form-model
                    ref="form"
                    hide-required-mark
                    :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                    :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
            >
                <a-form-model-item
                        label="实施状态："
                        class="requiredFormItem"
                >
                    <a-select v-model:value="implStatus" style="width: 120px" placeholder="请选择" v-if="!isTodo">
                        <a-select-option :value="0">未实施</a-select-option>
                        <a-select-option :value="1">实施中</a-select-option>
                        <a-select-option :value="2">已实施</a-select-option>
                    </a-select>
                    <a-input disabled v-else v-model="name"></a-input>
                </a-form-model-item>
            </a-form-model>

        </a-card>
        </template>
        <div class="page-btn-right-top">
            <a-button type="primary" @click="deal" v-if="!isTodo" :loading="loading">确定处理</a-button>
            <a-button  @click="$router.back()">关闭</a-button>
        </div>
        <EditFrom is-audit useBaseInfo @success="intiFinish"></EditFrom>
    </base-breadcrumb>
</template>

<script>
    import EditFrom from "../Approval/EditFrom"
    import { changeImpStatus } from "@/api/technology"
    import { finishBusinessTodo } from '@/api/commons'
    import moment from 'moment'
  export default {
    name: 'approve',
    components: {
      EditFrom
    },
    data() {
      return {
        implStatus: null,
        loading: false,
        title: '',
        isTodo: false,
        name: '已实施'
      }
    },
    created() {
      this.isTodo = this.$route.query.todoStatus == 1 ? true: false
    },
    methods: {
      intiFinish(form) {
        this.title = moment(form.submitDate).format('YYYY年MM月') + '实施状态'
        this.name = this.$route.query.remark

      },
       async deal() {
        if(this.implStatus===null) {
          this.$message.warning('请选择实施状态')
          return
        }
        const data = {
          constructionId: this.$route.query.id,
          implStatus: this.implStatus
        }
        try {
          this.loading= true
          await changeImpStatus(data)
          const name = ['未实施', '实施中', '已实施'][this.implStatus]
            await finishBusinessTodo({
              id: this.$route.query.messageId,
              remark: name
            })
          this.loading= false
          this.$message.success('提交成功')
          this.$router.back()
        } catch (e) {
          this.loading= false
        }

      }
    }
  }
</script>

<style scoped>

</style>